/**
 * Created by chenkun on 2017/6/8.
 */
import request from './../api/'
import {ajax} from '@/utils/'

var plugins = {};

for (var i = 0; i < request.length; i++) {
  if (typeof request[i] === 'object' && request[i].list && Array.isArray(request[i].list)) {
    for (var j = 0; j < request[i].list.length; j++) {
      // console.log('api_' + request[i].module + '_' + request[i].list[j].method)
      plugins['api_' + request[i].module + '_' + request[i].list[j].method] = (function (n, m) {
        return function ({type = request[n].list[m].type, path = request[n].list[m].path, data={}, fn,succFn, errFn,tokenFlag,noLoading, headers, opts}={}) {
          //request[n].list[m].type, request[n].list[m].path, data, fn, opts
          ajax.call(this, {
            type,
            path,
            data,
            fn,
            succFn,
            errFn,
            tokenFlag,
            noLoading,
            headers,
            opts
          });
        };
      })(i, j);
    }
  }
}

export default plugins
